package com.qiang.demo03;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Test01 {
    public static void main(String[] args) {

        TreeMap<Student, String> sds = new TreeMap<>();
        Student s1 = new Student("张三", 23);
        Student s2 = new Student("李四", 21);
        Student s3 = new Student("王五", 24);
        sds.put(s1, "江苏");
        sds.put(s2, "北京");
        sds.put(s3, "上海");
        Set<Student> keyset = sds.keySet();
        for (Student key : keyset) {
            String value = sds.get(key);
            System.out.println(key);
            System.out.println(value);
        }
        System.out.println("=============");

        Set<Map.Entry<Student, String>> et = sds.entrySet();
        for (Map.Entry<Student, String> ete : et) {
            Student key = ete.getKey();
            String value = ete.getValue();
            System.out.println(key);
            System.out.println(value);
        }

        System.out.println("=============");

        sds.forEach((Student key,String value) -> {
            System.out.println(key+"---"+value);
        });

      /* HashMap<Student, String> hm = new HashMap<Student, String>();

        //创建学生对象
        Student s1 = new Student("林青霞", 30);
        Student s2 = new Student("张曼玉", 35);
        Student s3 = new Student("王祖贤", 33);
        Student s4 = new Student("王祖贤", 33);

        //把学生添加到集合
        hm.put(s1, "西安");
        hm.put(s2, "武汉");
        hm.put(s3, "郑州");
        hm.put(s4, "北京");

        //遍历集合
        Set<Student> keySet = hm.keySet();
        for (Student key : keySet) {
            String value = hm.get(key);
            System.out.println(key.getName() + "," + key.getAge() + "," + value);
        }*/
    }
}
